package planit.view;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.util.Calendar;
import java.util.Date;

import javax.swing.AbstractAction;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.SpinnerDateModel;

import planit.controller.ControllerFactory;
import planit.controller.ControllerFactory.ControllerType;
import planit.model.EventType;

import com.toedter.calendar.JDateChooser;


/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
@SuppressWarnings("serial")
public class EventDialog extends javax.swing.JDialog {
	private JPanel jPanel1;
	private JTextField nameTextField;
	private JLabel descriptionLabel;
	private AbstractAction cancelAbstract;
	private JLabel durationLabel;
	private JLabel startLabel;
	private JSpinner durationSpinner;
	private JSpinner startTimeSpinner;
	private JLabel jLabel1;
	private JDateChooser jDateChooser1;
	private JTextArea descriptionTextArea;
	private JTextField typeTextField;
	private JButton jButton1;
	private JButton jButton2;
	private JTextField placeTextField;
	private JLabel typeLabel;
	private JLabel PlaceLabel;
	private JLabel nameLabel;

	{
		// Set Look & Feel
		try {
			javax.swing.UIManager
			.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public EventDialog() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			{	
				jPanel1 = new JPanel();
				GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
				getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1.setLayout(jPanel1Layout);
				jPanel1.setPreferredSize(new java.awt.Dimension(344, 305));
				jPanel1.setSize(360, 250);
				{
					nameLabel = new JLabel();
					nameLabel.setText("Name of Event");
					nameLabel.setBounds(6, 12, 87, 16);
				}
				{
					startLabel = new JLabel();
					startLabel.setText("Begins:");
				}
				{
					durationLabel = new JLabel();
					durationLabel.setText("Duration:");
				}
				{
					startTimeSpinner = new JSpinner();
					SpinnerDateModel model = new SpinnerDateModel();
					startTimeSpinner.setModel(model);
					JComponent editor = new JSpinner.DateEditor(startTimeSpinner, "HH:mm");
					startTimeSpinner.setEditor(editor);
					startTimeSpinner.setValue(new Date());
				}
				{
					durationSpinner = new JSpinner();
					SpinnerDateModel model = new SpinnerDateModel();
					durationSpinner.setModel(model);
					JComponent editor = new JSpinner.DateEditor(durationSpinner, "HH:mm");
					durationSpinner.setEditor(editor);
					Calendar tempCal = Calendar.getInstance();
					tempCal.set(0, 0, 0, 1, 0);
					durationSpinner.setValue(tempCal.getTime());
				}
				{
					jDateChooser1 = new JDateChooser();
					jDateChooser1.setDate(new Date());
				}
				{
					jLabel1 = new JLabel();
					jLabel1.setText("Date:");
				}
				{
					PlaceLabel = new JLabel();
					PlaceLabel.setText("Place");
					PlaceLabel.setBounds(6, 114, 31, 16);
				}
				{
					typeLabel = new JLabel();
					typeLabel.setText("Type");
					typeLabel.setBounds(6, 149, 26, 16);
				}
				{
					nameTextField = new JTextField();
					nameTextField.setBounds(99, 6, 239, 28);
				}
				{
					placeTextField = new JTextField();
					placeTextField.setBounds(99, 108, 239, 28);
				}
				{
					jButton1 = new JButton();
					jButton1.setText("Cancel");
					jButton1.setBounds(119, 289, 67, 28);
					jButton1.setAction(getCancelAbstract());
				}
				{
					jButton2 = new JButton();
					jButton2.setAction(ControllerFactory
							.getController(ControllerType.CREATE_EVENT));
					jButton2.getAction().putValue("EventDialog", this);
					jButton2.setText("Add");
					jButton2.setBounds(261, 294, 65, 28);
				}
				{
					typeTextField = new JTextField();
					typeTextField.setBounds(99, 143, 239, 28);
				}
				{
					descriptionLabel = new JLabel();
					descriptionLabel.setText("Description");
					descriptionLabel.setBounds(6, 183, 63, 16);
				}
				{
					descriptionTextArea = new JTextArea();
					descriptionTextArea.setBounds(99, 177, 239, 79);
				}
				jPanel1Layout.setHorizontalGroup(jPanel1Layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(jPanel1Layout.createParallelGroup()
								.addGroup(jPanel1Layout.createSequentialGroup()
										.addGroup(jPanel1Layout.createParallelGroup()
												.addComponent(descriptionLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
												.addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
														.addComponent(typeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
														.addGap(37))
														.addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
																.addComponent(PlaceLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
																.addGap(32)))
																.addGroup(jPanel1Layout.createParallelGroup()
																		.addComponent(durationLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 57, GroupLayout.PREFERRED_SIZE)
																		.addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
																				.addPreferredGap(durationLabel, startLabel, LayoutStyle.ComponentPlacement.INDENT)
																				.addComponent(startLabel, GroupLayout.PREFERRED_SIZE, 51, GroupLayout.PREFERRED_SIZE)))
																				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
																				.addGroup(jPanel1Layout.createParallelGroup()
																						.addComponent(durationSpinner, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 63, GroupLayout.PREFERRED_SIZE)
																						.addComponent(startTimeSpinner, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 63, GroupLayout.PREFERRED_SIZE))
																						.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
																						.addGroup(jPanel1Layout.createParallelGroup()
																								.addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
																										.addGroup(jPanel1Layout.createParallelGroup()
																												.addGroup(jPanel1Layout.createSequentialGroup()
																														.addGap(0, 0, Short.MAX_VALUE)
																														.addComponent(jButton1, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
																														.addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
																																.addPreferredGap(jButton1, jLabel1, LayoutStyle.ComponentPlacement.INDENT)
																																.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
																																.addGap(20)))
																																.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0, GroupLayout.PREFERRED_SIZE)
																																.addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 65, GroupLayout.PREFERRED_SIZE))
																																.addComponent(jDateChooser1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 136, GroupLayout.PREFERRED_SIZE)))
																																.addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
																																		.addComponent(nameLabel, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE)
																																		.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
																																		.addGroup(jPanel1Layout.createParallelGroup()
																																				.addComponent(descriptionTextArea, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 239, GroupLayout.PREFERRED_SIZE)
																																				.addComponent(typeTextField, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 239, GroupLayout.PREFERRED_SIZE)
																																				.addComponent(placeTextField, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 239, GroupLayout.PREFERRED_SIZE)
																																				.addComponent(nameTextField, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 239, GroupLayout.PREFERRED_SIZE))))
																																				.addContainerGap(6, 6));
				jPanel1Layout.setVerticalGroup(jPanel1Layout.createSequentialGroup()
						.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
								.addComponent(nameTextField, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(nameLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
										.addComponent(placeTextField, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
										.addComponent(PlaceLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
												.addComponent(typeTextField, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
												.addComponent(typeLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
												.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
												.addGroup(jPanel1Layout.createParallelGroup()
														.addComponent(descriptionTextArea, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
														.addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
																.addComponent(descriptionLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
																.addGap(63)))
																.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
																.addGroup(jPanel1Layout.createParallelGroup()
																		.addComponent(jDateChooser1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
																		.addComponent(startTimeSpinner, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
																		.addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
																				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
																				.addComponent(startLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
																				.addGap(6)))
																				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
																				.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
																						.addComponent(durationSpinner, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
																						.addComponent(durationLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
																						.addGap(0, 0, Short.MAX_VALUE)
																						.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
																								.addComponent(jButton1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
																								.addComponent(jButton2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
																								.addContainerGap(12, 12));
			}
			pack();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public EventType getEventType() {
		return new EventType(); 
	}

	public String getEventPlace() {
		return placeTextField.getText();
	}

	public String getEventName() {
		return nameTextField.getText();
	}

	public String getEventDescription() {
		return descriptionTextArea.getText();
	}

	public Date getEventDuration() {
		return (Date)durationSpinner.getValue();
	}

	public Date getEventDate() {
		return jDateChooser1.getDate();
	}

	public Date getEventStartTime() {
		return (Date)startTimeSpinner.getValue();
	}

	private AbstractAction getCancelAbstract() {
		if(cancelAbstract == null) {
			cancelAbstract = new AbstractAction("Cancel", null) {
				public void actionPerformed(ActionEvent evt) {
					dispose();
				}
			};
		}
		return cancelAbstract;
	}
}
